package util;

import java.awt.AWTEvent;
import java.awt.EventQueue;
import java.awt.Toolkit;
import java.awt.event.AWTEventListener;
import javax.swing.JOptionPane;

/**
 *
 * @author Gilberto 14/05/2012 13:38
 */
public class AtalhoTeclado {

    public AtalhoTeclado() {
        //construtor
        Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {

            @Override
            public void eventDispatched(AWTEvent event) {
            }
        }, AWTEvent.KEY_EVENT_MASK);
    }

    public static void main(String[] args) {
        EventQueue queue = new EventQueue() {

            @Override
            protected void dispatchEvent(AWTEvent event) {

                String a[], tecla[];

                if (!event.paramString().equals("")) {
                    if (event.paramString().substring(0, 5).equals("KEY_P")) {
                        a = event.paramString().split(",");
                        tecla = a[1].split("=");

                        switch (Integer.parseInt(tecla[1])) {
                            case 112:
                                JOptionPane.showMessageDialog(null, "F1");
                                break;
                            case 113:
                                JOptionPane.showMessageDialog(null, "F2");
                                break;
                            case 114:
                                JOptionPane.showMessageDialog(null, "F3");
                                break;
                            case 115:
                                JOptionPane.showMessageDialog(null, "F4");
                                break;
                            case 116:
                                JOptionPane.showMessageDialog(null, "F5");
                                break;
                            case 117:
                                JOptionPane.showMessageDialog(null, "F6");
                                break;
                            case 118:
                                JOptionPane.showMessageDialog(null, "F7");
                                break;
                            case 119:
                                JOptionPane.showMessageDialog(null, "F8");
                                break;
                            case 120:
                                JOptionPane.showMessageDialog(null, "F9");
                                break;
                            case 121:
                                JOptionPane.showMessageDialog(null, "F10");
                                break;
                            case 122:
                                JOptionPane.showMessageDialog(null, "F11");
                                break;
                            case 123:
                                JOptionPane.showMessageDialog(null, "F12");
                                break;
                            default:
                                break;
                        }
                    }
                }
            }
        };
        Toolkit.getDefaultToolkit().getSystemEventQueue().push(queue);
    }
}
